package alogrithm;

import java.util.ArrayList;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/10/18 13:23
 */
public class IsPail {

    public boolean isPail(ListNode head) {
        // write code here
        if (head == null) {
            return true;
        }
        ArrayList<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        int n = list.size();
        for (int i = 0; i < n / 2; ++i) {
            if (!list.get(i).equals(list.get(n - i - 1))) {
                return false;
            }
        }
        return true;
    }

    public class ListNode {
        int val;
        ListNode next = null;
    }
}
